<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>
            <%= htmlWebpackPlugin.options.title %>
        </title>
        <!-- Open Graph data -->
        <!-- <meta property="og:title" content="Title Here" /> -->
        <!-- <meta property="og:url" content="http://www.example.com/" /> -->
        <!-- <meta property="og:image" content="http://example.com/image.jpg" /> -->
        <!-- <meta property="og:description" content="Description Here" /> -->
        <script>
            var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
            document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')
        </script>
		<script>
		      window.wxUserInfo = localStorage.getItem('wxUserInfo');
		       window.TOKEN = localStorage.getItem('token');
		       if (!wxUserInfo) {
		           var code = location.search.substr(1).split('&').find(s => s.startsWith('code'));
		           code = code ? code.split('=').pop() : null;
		           if (code) {
		               var xhr = new XMLHttpRequest();
		               xhr.open('GET', '/api/auth/wechat?code=' + code, true);
		               xhr.addEventListener('load', function () {
		                   var res = JSON.parse(xhr.responseText);
		                   if (res.status === 200) {
		                       window.wxUserInfo = res.data.user;
		                       window.TOKEN = res.data.token;
		                       localStorage.setItem('wxUserInfo', JSON.stringify(wxUserInfo));
		                       localStorage.setItem('token', TOKEN);
		                   } else {
		                       alert(res.message);
		                       location.href = '/';
		                   }
		               });
		               xhr.addEventListener('error', function () {
		                   alert('请求用户信息失败');
		               });
		               xhr.send();
		           } else {
		               window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + window.APPID + '&redirect_uri=' + encodeURIComponent(window.location.href) + '&response_type=code&scope=snsapi_userinfo#wechat_redirect';
		           }
		       } else {
		           wxUserInfo = JSON.parse(wxUserInfo);
		       }
		  
		 </script>
        <link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
    </head>
    <body>
        <noscript>
            <strong>Please enable JavaScript to continue.</strong>
        </noscript>
        <div id="app"></div>
        <!-- built files will be auto injected -->
    </body>
</html>